﻿package mortal.game.view.task.view
{
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.component.gLinkText.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.task.data.*;
    import mortal.mvc.core.*;

    public class TaskItemDesc extends GSprite
    {
        private var _pane:GScrollPane;
        private var _descContianer:GSprite;
        private var _desc:Array;
        private var _target:Array;
        private var _reward:TaskReward;
        private var _btnGiveup:GButton;
        private var _taskInfo:TaskInfo;

        public function TaskItemDesc()
        {
            return;
        }// end function

        public function get taskInfo() : TaskInfo
        {
            return this._taskInfo;
        }// end function

        public function set taskInfo(param1:TaskInfo) : void
        {
            var _loc_3:int = 0;
            var _loc_8:String = null;
            var _loc_9:Array = null;
            var _loc_10:int = 0;
            var _loc_11:GLinkTextData = null;
            var _loc_12:GLinkText = null;
            this._taskInfo = param1;
            var _loc_2:* = Cache.instance.task.getLinkTextData(this._taskInfo.stask.code);
            if (_loc_2 == null)
            {
                return;
            }
            _loc_3 = this._taskInfo.curStep;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            while (_loc_6 < _loc_2.length)
            {
                
                _loc_8 = Language.getStringByParam(20160, GameConst.Num_ZhongWen[_loc_6]);
                _loc_9 = _loc_2[_loc_6];
                _loc_10 = 0;
                while (_loc_10 < _loc_9.length)
                {
                    
                    _loc_11 = _loc_9[_loc_10];
                    _loc_12 = this.getDescTxt(_loc_4);
                    _loc_12.widthConst = 350;
                    _loc_12.x = 0;
                    if (_loc_3 == _loc_6)
                    {
                        _loc_12.filters = [];
                    }
                    else
                    {
                        _loc_12.filters = [FilterConst.colorFilter];
                    }
                    if (_loc_10 == 0)
                    {
                        _loc_12.setLinkText(_loc_11, "", _loc_8 + ":");
                    }
                    else
                    {
                        _loc_12.setLinkText(_loc_11);
                        _loc_12.x = 40;
                    }
                    _loc_12.y = _loc_5;
                    _loc_5 = _loc_12.y + _loc_12.height;
                    _loc_4++;
                    _loc_10++;
                }
                _loc_6++;
            }
            DisplayUtil.delNotUse(this._desc, _loc_4, true);
            this._pane.source = this._descContianer;
            this._pane.drawNow();
            _loc_4 = 0;
            _loc_9 = _loc_2[_loc_3];
            if (_loc_9 == null && _loc_3 > 0)
            {
                _loc_9 = _loc_2[(_loc_3 - 1)];
            }
            var _loc_7:int = 108;
            _loc_10 = 0;
            while (_loc_10 < _loc_9.length)
            {
                
                _loc_11 = _loc_9[_loc_10];
                if (_loc_11.isLieMoTask)
                {
                    _loc_7 = 95;
                }
                _loc_12 = this.getTargetTxt(_loc_4);
                _loc_12.setLinkText(_loc_11);
                _loc_12.widthConst = 310;
                _loc_12.y = _loc_4 * 18 + _loc_7;
                _loc_4++;
                _loc_10++;
            }
            DisplayUtil.delNotUse(this._target, _loc_4, true);
            this._reward.updateRewards(this._taskInfo.stask.rewards);
            this.updateGiveupBtn();
            return;
        }// end function

        private function updateGiveupBtn() : void
        {
            if (this._taskInfo == null)
            {
                DisplayUtil.removeMe(this._btnGiveup);
            }
            else if (this._taskInfo.isCanget())
            {
                DisplayUtil.removeMe(this._btnGiveup);
            }
            else if (this._btnGiveup.parent == null)
            {
                this.addChild(this._btnGiveup);
            }
            return;
        }// end function

        private function getTargetTxt(param1:int) : GLinkText
        {
            var _loc_2:* = this._target[param1];
            if (_loc_2 == null)
            {
                _loc_2 = UICompomentPool.getUICompoment(GLinkText);
                this._target[param1] = _loc_2;
                this.addChild(_loc_2);
            }
            _loc_2.isShowNum = true;
            _loc_2.isShowFlyBoot = true;
            return _loc_2;
        }// end function

        private function getDescTxt(param1:int) : GLinkText
        {
            var _loc_2:* = this._desc[param1];
            if (_loc_2 == null)
            {
                _loc_2 = UICompomentPool.getUICompoment(GLinkText);
                this._desc[param1] = _loc_2;
                _loc_2.isShowFlyBoot = false;
                _loc_2.isShowNum = false;
                this._descContianer.addChild(_loc_2);
            }
            return _loc_2;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._pane = UIFactory.gScrollPanel(0, 0, 360, 70, this);
            this._descContianer = UICompomentPool.getUICompoment(GSprite);
            this._reward = UICompomentPool.getUICompoment(TaskReward);
            this._reward.y = 210;
            this.addChild(this._reward);
            this._desc = [];
            this._target = [];
            this._btnGiveup = UIFactory.gButton(Language.getString(20164), 290, 305, 60, 25, null, "ButtonNew");
            this._btnGiveup.configEventListener(MouseEvent.CLICK, this.giveupHandler);
            return;
        }// end function

        private function giveupHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskGiveupTask, this._taskInfo));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            DisplayUtil.delNotUse(this._desc, 0, param1);
            this._desc = null;
            DisplayUtil.delNotUse(this._target, 0, param1);
            this._target = null;
            this._pane.dispose(param1);
            this._pane = null;
            this._descContianer.dispose(param1);
            this._descContianer = null;
            this._reward.dispose(param1);
            this._reward = null;
            this._btnGiveup.dispose(param1);
            this._btnGiveup = null;
            this._taskInfo = null;
            this._target = null;
            return;
        }// end function

    }
}
